package com.baseweb.webadmin.core.model.mapper;

import com.baseweb.webadmin.core.model.pojo.ByMoneyLog;
import com.baseweb.webadmin.core.model.pojo.ByMoneyLogExample;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;

public interface ByMoneyLogMapper {
    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_money_log
     *
     * @mbggenerated Sat Feb 18 10:14:39 CST 2017
     */
    int countByExample(ByMoneyLogExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_money_log
     *
     * @mbggenerated Sat Feb 18 10:14:39 CST 2017
     */
    int deleteByExample(ByMoneyLogExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_money_log
     *
     * @mbggenerated Sat Feb 18 10:14:39 CST 2017
     */
    @Delete({
        "delete from by_money_log",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_money_log
     *
     * @mbggenerated Sat Feb 18 10:14:39 CST 2017
     */
    @Insert({
        "insert into by_money_log (user_id, money_type, ",
        "descn, amount, create_time, ",
        "update_time)",
        "values (#{userId,jdbcType=INTEGER}, #{moneyType,jdbcType=INTEGER}, ",
        "#{descn,jdbcType=VARCHAR}, #{amount,jdbcType=DECIMAL}, #{createTime,jdbcType=TIMESTAMP,typeHandler=com.baseweb.mybatis.typehandler.JodaDateTime2TimestampTypeHandler}, ",
        "#{updateTime,jdbcType=TIMESTAMP,typeHandler=com.baseweb.mybatis.typehandler.JodaDateTime2TimestampTypeHandler})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Integer.class)
    int insert(ByMoneyLog record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_money_log
     *
     * @mbggenerated Sat Feb 18 10:14:39 CST 2017
     */
    int insertSelective(ByMoneyLog record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_money_log
     *
     * @mbggenerated Sat Feb 18 10:14:39 CST 2017
     */
    List<ByMoneyLog> selectByExample(ByMoneyLogExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_money_log
     *
     * @mbggenerated Sat Feb 18 10:14:39 CST 2017
     */
    @Select({
        "select",
        "id, user_id, money_type, descn, amount, create_time, update_time",
        "from by_money_log",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @ResultMap("BaseResultMap")
    ByMoneyLog selectByPrimaryKey(Integer id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_money_log
     *
     * @mbggenerated Sat Feb 18 10:14:39 CST 2017
     */
    int updateByExampleSelective(@Param("record") ByMoneyLog record, @Param("example") ByMoneyLogExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_money_log
     *
     * @mbggenerated Sat Feb 18 10:14:39 CST 2017
     */
    int updateByExample(@Param("record") ByMoneyLog record, @Param("example") ByMoneyLogExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_money_log
     *
     * @mbggenerated Sat Feb 18 10:14:39 CST 2017
     */
    int updateByPrimaryKeySelective(ByMoneyLog record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_money_log
     *
     * @mbggenerated Sat Feb 18 10:14:39 CST 2017
     */
    @Update({
        "update by_money_log",
        "set user_id = #{userId,jdbcType=INTEGER},",
          "money_type = #{moneyType,jdbcType=INTEGER},",
          "descn = #{descn,jdbcType=VARCHAR},",
          "amount = #{amount,jdbcType=DECIMAL},",
          "create_time = #{createTime,jdbcType=TIMESTAMP,typeHandler=com.baseweb.mybatis.typehandler.JodaDateTime2TimestampTypeHandler},",
          "update_time = #{updateTime,jdbcType=TIMESTAMP,typeHandler=com.baseweb.mybatis.typehandler.JodaDateTime2TimestampTypeHandler}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(ByMoneyLog record);

    /**
     * 查询用户的钱包流水 根据userId Page
     * */
    @Select({
            "select * from ",
            "(select",
            "* ",
            "from by_money_log ",
            "where user_id = #{0} ",
            "order by create_time desc) as ok ",
            "LIMIT #{1},#{2}"
    })
    @ResultMap("BaseResultMap")
    List<ByMoneyLog> findAllMoneyLogByUserIdPage(Integer userId,int page,int pageNum);

    /**
     * 查询用户的钱包流水 根据userId count
     * */
    @Select({
            "select count(*) ",
            "from by_money_log ",
            "where user_id = #{0} ",
    })
    int countMoneyLogByUserIdPage(Integer userId);
}